<?php

/* Bootstrap */
require '../application/bootstrap.php';


$response = new Zend_Controller_Response_Http();

try {
    // Write message to file
    if (file_exists(PEXI_ROOT_DIR . '/tmp/' . $_POST['id'] . '.txt')) {
        throw new Zend_Exception('File "' . $_POST['id'] . '.txt" already exists');
    }
    file_put_contents(PEXI_ROOT_DIR . '/tmp/' . $_POST['id'] . '.txt', $_POST['message']);
    $response->setHttpResponseCode(200);
} catch (Zend_Exception $e) {
    $response->setHttpResponseCode(500);
}

$response->sendResponse();